package com.bringway.global.constant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;

/*
* @author 作者 xuef
* @version 创建时间：2016年1月12日 上午9:39:35
* 类说明
* excel导出头设置，数据格式转换
* 
*/
public class ExcelHeadConstant {
	
	/**
	 * 附件信息导出excel
	 * 将查询结果转为导出Excel时需要的格式
	 * @param nodeArray 查询结果
	 * @return 转换结果
	 * @throws JSONException
	 */
	public static List<String[]> getAttExportSearchResultData(List<Map<String, Object>> list)
			throws JSONException{
		List<String[]> resultList = new ArrayList<String[]>();
		String[] header = { "ID", "OPER_USER_ID(操作人ID)", "OPER_USER_NAME(操作人姓名)", "OPER_DATE(操作时间)", "COMMENT(备注)"};
		resultList.add(header);
		String[] lineData = null;
		JSONObject jsObj = null;
		for (int i = 0; i < list.size(); i++) {
			lineData = new String[header.length];
			Map<String, Object> map = list.get(i);
			jsObj  = JSONObject.fromObject(map);
			lineData[0] = jsObj.optString("ID");
			lineData[1] = jsObj.optString("OPER_USER_ID");
			lineData[2] = jsObj.optString("OPER_USER_NAME");
			lineData[3] = jsObj.optString("OPER_DATE");
			lineData[4] = jsObj.optString("COMMENT");
			resultList.add(lineData);
		}
		return resultList;
	}
	
	/**
	 * POS单回款信息导出excel
	 * 将查询结果转为导出Excel时需要的格式
	 * @param nodeArray 查询结果
	 * @return 转换结果
	 * @throws JSONException
	 */
	public static List<String[]> getPosHkExportSearchResultData(List<HashMap<String, String>> list)
			throws JSONException{
		List<String[]> resultList = new ArrayList<String[]>();
		String[] header = { "POS单号", "还款状态", "债权编号", "期限（天）","债权计息日期", "债权回款日期",
							"投资金额", "投资时间", "预计收益额", "预计还款金额","POS平台", "客户经理员工号",
							"客户姓名", "客户手机号码", "客户性别", "客户身份证号码", "客户回款银行名称", "客户回款银行卡号码",
							"客户来源", "录入人员", "审核人员", "审核时间", "审核内容", "回款操作人",
							"回款时间", "回款备注"};
		resultList.add(header);
		String[] lineData = null;
		JSONObject jsObj = null;
		for (int i = 0; i < list.size(); i++) {
			lineData = new String[header.length];
			Map<String, String> map = list.get(i);
			jsObj  = JSONObject.fromObject(map);
			lineData[0] = jsObj.optString("POS_CODE");
			String hkState = jsObj.optString("HK_STATE");
			if("00".equals(hkState)){
				lineData[1] = "待回款";
			}else if("01".equals(hkState)){
				lineData[1] = "回款完成";
			}else if("02".equals(hkState)){
				lineData[1] = "回款失败";
			}else{
				lineData[1] = "待回款";
			}
			lineData[2] = jsObj.optString("ZQID");
			lineData[3] = jsObj.optString("QX");
			lineData[4] = jsObj.optString("JXRQ");
			lineData[5] = jsObj.optString("HKRQ");
			
			lineData[6] = jsObj.optString("TCJE");
			lineData[7] = jsObj.optString("TZSJ");
			lineData[8] = jsObj.optString("YS_TZSY");
			lineData[9] = jsObj.optString("YJ_HKJE");
			String posPlatForm = jsObj.optString("POS_PLATFORM");
			if("00".equals(posPlatForm)){
				lineData[10] = "未知";
			}else if("01".equals(posPlatForm)){
				lineData[10] = "通联";
			}else if("02".equals(posPlatForm)){
				lineData[10] = "银盛";
			}else{
				lineData[10] = "其它";
			}
			
			lineData[11] = jsObj.optString("POS_BIZ_GYH");
			lineData[12] = jsObj.optString("POS_OWNER_USER_ID");
			lineData[13] = jsObj.optString("POS_OWNER_SJHM");
			String posCusSex = jsObj.optString("POS_CUSTOMER_SEX");
			if("00".equals(posCusSex)){
				lineData[14] = "未知";
			}else if("01".equals(posCusSex)){
				lineData[14] = "男";
			}else if("02".equals(posCusSex)){
				lineData[14] = "女";
			}else{
				lineData[14] = "其它";
			}
			lineData[15] = jsObj.optString("POS_CUSTOMER_SFZ");
			lineData[16] = jsObj.optString("POS_CUSTOMER_HK_YHMC");
			
			lineData[17] = jsObj.optString("POS_CUSTOMER_HK_CARD_NUM");
			String posCusLy = jsObj.optString("POS_CUSTOMER_LY");
			if("00".equals(posCusLy)){
				lineData[18] = "未知";
			}else if("01".equals(posCusLy)){
				lineData[18] = "陌生拜访";
			}else if("02".equals(posCusLy)){
				lineData[18] = "驻点";
			}else if("03".equals(posCusLy)){
				lineData[18] = "缘故";
			}else if("04".equals(posCusLy)){
				lineData[18] = "转介绍";
			}else{
				lineData[18] = "其它";
			}
			lineData[19] = jsObj.optString("OPER_USER_ID");
			lineData[20] = jsObj.optString("SH_USER_ID");
			lineData[21] = jsObj.optString("SH_DATE");
			lineData[22] = jsObj.optString("SH_CONTENT");
			lineData[23] = jsObj.optString("HK_USER_ID");
			if("null".equals(lineData[23])){
				lineData[23] = "";
			}
			lineData[24] = jsObj.optString("HK_DATE");
			if("null".equals(lineData[24])){
				lineData[24] = "";
			}
			lineData[25] = jsObj.optString("HK_CONTENT");
			if("null".equals(lineData[25])){
				lineData[25] = "";
			}
			resultList.add(lineData);
		}
		return resultList;
	}
}
